package com.xinghanlaser.applet.base.oss.config;


import com.xinghanlaser.applet.base.oss.service.OssService;
import com.xinghanlaser.applet.base.oss.service.impl.OssServiceImpl;
import lombok.AllArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.annotation.Resource;

/**
 * @description OSS自动配置类
 *
 * 【使用步骤】
 *  1. 导入oss-component包
 *  2. 在application.yaml需要添加的如下配置：
 *      oss:
 *        # 开启OSS功能
 *        enable: true
 *        # 服务端地址
 *        endpoint: http://124.221.236.196:9000
 *        # 账号
 *        accessKey: grandpa
 *        # 密码
 *        secretKey: Landong540788
 *        # 桶名
 *        bucketName: grandpa
 *
 *      spring:
 *        servlet:
 *          multipart:
 *            max-file-size: 200MB
 *            max-request-size: 200MB
 *  3. 注入OssService接口,调用对应方法操作对象
 *
 * @author 阿爷
 * @createDate  2023/8/28
 */
@AllArgsConstructor
@EnableConfigurationProperties({OssProperties.class})
@Configuration
public class OssAutoConfiguration {
    @Resource
    private OssProperties ossProperties;

    @Bean
    @Primary
    @ConditionalOnMissingBean(OssService.class)
    @ConditionalOnProperty(name = "oss.enable",havingValue = "true")
    public OssService ossService(){
        return new OssServiceImpl(ossProperties);
    }
}
